﻿# -*- coding:utf-8 -*-
import os
import re
import json
from bs4 import BeautifulSoup
import pandas as pd

def txt_wrap_by(start_str, end, html):
    """
    截取字符串html中从start_str到end的部分，不包含start_str和end
    """
    start = html.find(start_str)
    if start >= 0:
        start += len(start_str)
        end = html.find(end, start)
        if end >= 0:
            return html[start:end].strip()

class ResumeParsing:
    def __init__(self,filename):
        #file = filename.read()
        self.soup = BeautifulSoup(filename)
    def DefineFiletype(self):
        jianlitype = ''
        t = self.soup.find('title')
        if (t != None):
            if ('智联招聘' in t.get_text()):
                jianlitype = 'zhiliandoc'
            elif ('智联卓聘' in t.get_text()):
                 jianlitype = 'zhuopinhtm'
            elif ('智联简历' in t.get_text()):
                jianlitype = ('zhilianhtm')
            elif ('58同城' in t.get_text()):
                jianlitype = ('tongcheng58')
            elif ('简历ID：' in t.get_text()):
                jianlitype = ('pin101')
            elif ('人才啊' in t.get_text()):
                jianlitype = ('rencaia')
            elif ('个人简历' in t.get_text()):
                jianlitype = ('jianlika')
            else:
                temp = self.soup.find_all('span')
                if (temp != None and jianlitype == '' and (temp[0].get_text() in '个人信息' or '姓名' in temp[0].get_text())):
                    jianlitype = ('zhuopin')
        else:
            type51 = self.soup.find('td',style = "padding:0 25px;height:54px;font-size:16px;font-weight:bold;color:#818ba3;")
            if (type51 != None and jianlitype == '' and '51job简历' in type51.get_text()):
                jianlitype = ('job51')
            type2 = self.soup.find('div')
            if (type2 != None and jianlitype == '' and 'http://www.WizBrother.com' in type2.get_text()):
                jianlitype = ('job51')
            area = self.soup.find('div', class_="resume-header resume-mutil-header")
            if (area != None and jianlitype == ''):
                if ('简历名称' in area.get_text()):
                    jianlitype = ('fenjianli')
            zhilianname = self.soup.find('p', style='text-align:left;tab-stops:366.0pt')
            if (zhilianname != None and jianlitype == ''):
                jianlitype = ('zhiliandoc')
            basic = self.soup.find('span',style='font-family:宋体;mso-ascii-font-family:Tahoma;mso-hansi-font-family:Tahoma')
            if (jianlitype == ''and basic!=None and('男' in  basic.get_text() or '女' in  basic.get_text()) ):
                jianlitype = 'liepin'
            liepintxt = self.soup.find('span',
                                       style='font-size:15.0pt; font-family:宋体;mso-ascii-font-family:STSong-Light;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:STSong-Light; mso-bidi-font-family:STSong-Light;color:#404040;mso-font-kerning:1.0pt')
            liepin2=self.soup.find('b')
            if (jianlitype == '' and liepintxt != None and ('个人信息' == liepintxt.get_text())):
                jianlitype = 'liepin'
            if (jianlitype == '' and liepin2 != None and ( '主动应聘职位:' in liepin2)):
                jianlitype = 'liepin'
            type512 = self.soup.find_all('span', style="color:#256fb8;")
            if (type512 != None  and jianlitype == ''):
                temp1 = type512[0].get_text()
                if(len(type512)>3):
                    temp1=type512[3].get_text()
                if re.findall('\d{4}-\d{2}-\d{2}', temp1) != []:
                    jianlitype = ('job51')
        return jianlitype

    def fenjianli(self,filename):
        soup=self.soup###空值定义区,防数值重复
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        time = ''
        company = ''
        workexplist='['
        eduexplist='['
        ###################提取姓名
        basic = soup.select('#resume-info-id')
        if(basic!=[]):
            name = basic[0].find_next().get_text()
            info = basic[0].select('.info')
            if(info!=[]):
                try:
                    detail = info[0].select('.important-content')
                    detail2 = detail[0].select('span')
                    sex = detail2[0].get_text()
                    age1 = detail2[1].get_text()
                    age = re.sub('（.*?）', '', age1)
                    exp = detail2[2].get_text()
                    edu = detail2[3].get_text()
                    wed = detail2[4].get_text()
                except Exception:
                    print("###########fenjianli(sex、age等信息出现错误)#############")
                try:
                    parea = info[0].select('p')
                    placestr = parea[1].get_text()
                    placelist = placestr.split('|')
                    placelist2 = placelist[0].split('：')
                    place = placelist2[1]
                except Exception:
                    print("###########fenjianli(place等信息出现错误)#############")
            try:
                linkarea = basic[0].select('.contact')
                tel = linkarea[0].select('.phone')[0].get_text()
                mail = linkarea[0].select('.email')[0].get_text()
            except Exception:
                print("###########fenjianli(tel、mail等信息出现错误)#############")
        try:
            expect = soup.select('#resume-want-id')
            expect1 = expect[0].select('.content')
            expect2 = expect1[0].select('.value')
            city = expect2[0].get_text()
            salary = expect2[1].get_text()
        except Exception:
            print("###########fenjianli(期望工作地区和期望月薪错误)#############")
        ####提取最近一份工作
        try:
            workarea = soup.select('#work-experience-id')
            work1 = workarea[0].select('.content')
            work2 = work1[0].select('.split-title2')
            for i in range (0,len(work2)):
                try:
                    workTitle = ''
                    workCompany = ''
                    startTime = ''
                    endTime = ''
                    workContent = ''
                    workTemplate = {
                        "startTime": "#STARTTIME#",
                        "endTime": "#ENDTIME#",
                        "workCompany": "#WORKCOMPANY#",
                        "workTitle": "#WORKTITLE#",
                        "workContent": "#WORKCONTENT#"}
                    worktempstr = work2[i].get_text()
                    worktemlist = worktempstr.split('|')
                    lenwork = len(worktemlist)
                    if lenwork == 3:
                        workTitle = worktemlist[1]
                    elif lenwork == 2:
                        workTitle = worktemlist[0]
                    try:
                        workcompany1 = work1[0].select('.split-title1')
                        workCompany = workcompany1[i].get_text().split('  ')[1]
                        workTime = workcompany1[i].get_text().split('  ')[0]
                        startTime = workTime.split('-')[0]
                        endTime = workTime.split('-')[1]
                    except Exception:
                        print("###########fenjianli(company信息出现错误)#############")
                    try:
                        workContentlist = work1[0].select('.table-value')
                        workContent = workContentlist[i].get_text()
                        workContent = re.sub('\t', '', workContent)
                        workContent = re.sub('\n', '', workContent)
                    except Exception:
                        print("###########fenjianli(工作职责出现错误)#############")
                    workTemplate['startTime'] = startTime
                    workTemplate['endTime'] = endTime
                    workTemplate['workTitle'] = workTitle
                    workTemplate['workCompany'] = workCompany
                    workTemplate['workContent'] = workContent
                    if (i == 0):
                        work = workTitle
                        company = workCompany
                    if (i == len(work2) - 1):
                        workexplist = workexplist + json.dumps(workTemplate) + ']'
                    else:
                        workexplist = workexplist + json.dumps(workTemplate) + ','
                except Exception:
                    continue
        except Exception:
            print("###########fenjianli(工作经历错误)#############")
        ####提取学校和专业
        try:
            eduarea = soup.select('#education-experience-id')
            edu1 = eduarea[0].select('.content')[0].get_text()
            eduTemplate={
                "eduStart": "",
                "eduEnd": "",
                "education": "",
                "eduSchool": "",
                "eduMaster": ""}
            edutemp=edu1.split('\n')
            edulist=[]
            for each in edutemp:
                if each!='':
                    each = re.sub('\t', '', each)
                    edulist.append(each)
            for i in range(0,len(edulist)):
                try:
                    edu3 = edulist[i].split('  ')
                    eduTemplate['eduStart'] = edu3[0].split('-')[0]
                    eduTemplate['eduEnd'] = edu3[0].split('-')[1]
                    eduTemplate['eduSchool'] = edu3[1]
                    if (len(edu) > 3):
                        eduTemplate['education'] = edu3[3]
                        eduTemplate['eduMaster'] = edu3[2]
                    else:
                        eduTemplate['education'] = edu3[2]
                    if (i == 0):
                        school = edu3[1]
                        master = edu3[2]
                    if (i == len(edulist) - 1):
                        eduexplist = eduexplist + json.dumps(eduTemplate) + ']'
                    else:
                        eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                except Exception:
                    continue
        except Exception:
            print("###########fenjianli(学校和专业错误)#############")
        #####提取更新时间####
        try:
            time1 = soup.select('#resume-mutil-header-id')
            time2 = time1[0].select('p')
            for each in time2:
                if '简历更新时间' in each.get_text():
                    time3 = each.get_text()
                    time4 = time3.split('：')
                    if len(time4) > 1:
                        time = time4[1]
        except Exception:
            print("###########fenjianli(学校和专业错误)#############")
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for each in people1:
            each = re.sub('\n', '', each)
            each = re.sub('\s', '', each)
            each = re.sub('\|', '', each)
            each = re.sub('\t', '', each)
            people.append(each)
        return people
    def pin101(self,filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        time = ''
        company = ''
        workexplist = '['
        eduexplist = '['
        try:
            namearea = soup.select('span.c3')
            name = namearea[0].select('b')[0].get_text()
            ########居住地
            place = soup.find('td', width="42%", height="20").get_text()
        except Exception:
            print("###########pin101(tel、mail#############")
        #####提取经验、性别和年龄
        try:
            basic = soup.select('span.blue')
            basic0 = basic[0].select('b')[0].get_text()
            basic1list = basic0.split('|')
            for each in basic1list:
                if '工作经验' in each:
                    exp = each
                if '男' in each or '女' in each:
                    sex = each
                if '岁' in each:
                    age = re.findall('.*?岁', each)[0]
        except Exception:
            print("###########pin101(经验、性别和年龄错误#############")
        ####学历
        try:
            eduarea = soup.find_all('td', width="49%", colspan="2")[0]
            edu1 = eduarea.select('td[align="left"]')
            edu = edu1[1].get_text()
            master = edu1[2].get_text()
            school = edu1[3].get_text()
        except Exception:
            print("###########pin101(tel、mail#############")
        #####电话
        try:
            telarea = soup.find_all('td', height="20", colspan="3", align="left")
            tel1 = telarea[0].get_text()
            if re.findall('1\d{10}', tel1) != []:
                tel = re.findall('1\d{10}', tel1)[0]
            ######电子邮箱
            mail = telarea[1].get_text()
        except Exception:
            print("###########pin101(tel、mail#############")
        #######最近工作
        try:
            work1 = soup.find('span', class_='blue c9')
            work2 = work1.select('b')[0]
            work3 = work2.get_text()
            if work3 == '最近工作':
                work4 = work1.find_parents(limit=3)[2]
                work5 = work4.select('td[width]')
                for each in work5:
                    if each.get_text() == '职　位：':
                        work6 = each
                        work = work6.find_next().get_text()
                    if each.get_text() == '公　司：':
                        company1 = each
                        company = company1.find_next().get_text()
        except Exception:
            print("###########pin101(work错误#############")
        #####提取目标地点和薪资
        edutag=-1
        eduexptxt = []
        worktag=-1
        workexptxt=[]
        try:
            jobexparea = soup.find_all('td',align="left" ,valign="middle" )
            for each in jobexparea:
                jobexptxt = each.get_text()
                if("工作经验" == jobexptxt):
                    worktag = 1
                if (jobexptxt in ['项目经验','教育经历']):
                    worktag = -1
                if ("教育经历" == jobexptxt):
                    edutag = 1
                if (jobexptxt in ['语言能力', 'IT 技能']):
                    edutag = -1
                if (edutag == 1) and jobexptxt != '':
                    eduexptxt.append(jobexptxt)
                if(worktag==1) and jobexptxt!='':
                    workexptxt.append(jobexptxt)
        except Exception:
            print("###########期望薪资#############")
        try:
            jobarea = soup.find_all('td', class_="text_left")
            for each in jobarea:
                jobtxt = each.get_text()
                if '目标地点' in jobtxt:
                    city = each.select('span')[0].get_text()
                if '期望薪资' in jobtxt:
                    salary = each.select('span')[0].get_text()
        except Exception:
            print("###########期望薪资#############")
        try:
            for i in range(1, len(workexptxt)):
                workexptxtlist=workexptxt[i].split('\n')
                worktxtlist=[]
                for worktxt in workexptxtlist:
                    worktxt = re.sub('\s', '', worktxt)
                    if worktxt!='':
                        worktxtlist.append(worktxt)
                workTitle = ''
                workCompany = ''
                startTime = ''
                endTime = ''
                workContent = ''
                workTemplate = {
                    "startTime": "#STARTTIME#",
                    "endTime": "#ENDTIME#",
                    "workCompany": "#WORKCOMPANY#",
                    "workTitle": "#WORKTITLE#",
                    "workContent": "#WORKCONTENT#"}
                workTime = worktxtlist[0].split('：')[0]
                startTime = workTime.split('--')[0]
                endTime = workTime.split('--')[1]
                workCompany = worktxtlist[0].split('：')[1]
                if(len(worktxtlist)==6):
                   workTitle =  worktxtlist[4]
                   workContent = worktxtlist[5]
                workTemplate['startTime'] = startTime
                workTemplate['endTime'] = endTime
                workTemplate['workTitle'] = workTitle
                workTemplate['workCompany'] = workCompany
                workTemplate['workContent'] = workContent
                if (i == 1):
                    work = workTitle
                    company = workCompany
                if (i == len(workexptxt)-1):
                    workexplist = workexplist + json.dumps(workTemplate)
                else:
                    workexplist = workexplist + json.dumps(workTemplate) + ','
            workexplist=workexplist+']'
        except Exception:
            print("###########pin101工作经历错误#############")
        try:
            for i in range(1, len(eduexptxt)):
                eduTemplate = {
                    "eduStart": "",
                    "eduEnd": "",
                    "education": "",
                    "eduSchool": "",
                    "eduMaster": ""}
                edutemp = eduexptxt[i].split('\n')
                edutxtlist = []
                for edueach in edutemp:
                    if edueach != '':
                        edutxtlist.append(edueach)
                try:
                    eduTemplate['eduStart'] = edutxtlist[0].split('--')[0]
                    eduTemplate['eduEnd'] = edutxtlist[0].split('--')[1]
                    eduTemplate['eduSchool'] = edutxtlist[1]
                    if (len(edutxtlist) >= 4):
                        eduTemplate['education'] = edutxtlist[3]
                        eduTemplate['eduMaster'] = edutxtlist[2]
                    else:
                        eduTemplate['education'] = edutxtlist[2]
                    if (i == 0):
                        school =edutxtlist[1]
                        master = edutxtlist[2]
                    if (i == len(eduexptxt) - 1):
                        eduexplist = eduexplist + json.dumps(eduTemplate)
                    else:
                        eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                except Exception:
                        print('教育经历错误')
            eduexplist = eduexplist+ ']'
        except Exception:
            print("###########pin101(提取教育经历错误)#############")
        #####更新日期####
        try:
            time1 = soup.select('#lblResumeUpdateTime')[0].get_text()
            time2 = time1.split('：')
            if len(time2) > 1:
                time = time2[1]
        except Exception:
            print("###########期望薪资#############")
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for each in people1:
            each = re.sub('\n', '', each)
            each = re.sub('\s', '', each)
            each = re.sub('\|', '', each)
            each = re.sub('\t', '', each)
            people.append(each)
        print(people)
        return people
    def rencaia(self,filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        time = ''
        company = ''
        workexplist = '['
        eduexplist = '['
        try:
            ####姓名、性别、年龄、所在地、工作经验、手机、邮箱
            if(soup.find('label')!=None):
                time = soup.find('label').string
            if(soup.find('div', style='font-size:20px;')!=None):
                name = soup.find('div', style='font-size:20px;').string
            #####更新日期####
            try:
                explist = soup.find_all('td', style="height: 24px; ")
                for i in range(0, len(explist)):
                    if ('期望地点' in explist[i].get_text()):
                        city = explist[i + 1].get_text()
                    if ('期望月薪' in explist[i].get_text()):
                        salary = explist[i + 1].get_text()
            except Exception:
                print("###########期望地点、期望薪资#############")
            try:
                basic = soup.find_all('td', style='padding-bottom: 26px; padding-top: 24px;')
                if (basic!=[]):
                    basicstr = basic[0].get_text()
                    basicstr = re.sub('\n', '', basicstr)
                    basicstr = re.sub('\s', '', basicstr)
                    basiclist = basicstr.split('|')
                    sexlist = list(basiclist[0])
                    sex = sexlist[len(sexlist) - 1]
                    age = basiclist[1]
                    exp = basiclist[2]
                    place = basiclist[3]
                    tellist = basiclist[4].split('：')
                    tel = tellist[1]
                    maillist = basiclist[5].split('：')
                    mail = maillist[1]
            except Exception:
                print("###########姓名、性别、年龄、所在地、工作经验、手机、邮箱错误#############")
            try:
                #########学校、专业、学历
                area = soup.find_all('tr', style="vertical-align:top;")
                area1 = area[0].select('td')
                school = area1[1].get_text()
                master = area1[2].get_text()
                edu = area1[3].get_text()
                for i in range(0, len(area)):
                    try:
                        edutxtlist = area[i].select('td')
                        eduTemplate = {
                            "eduStart": "",
                            "eduEnd": "",
                            "education": "",
                            "eduSchool": "",
                            "eduMaster": ""}
                        try:
                            eduTime = edutxtlist[0].get_text()
                            eduTemplate['eduStart'] = eduTime.split('-')[0]
                            eduTemplate['eduEnd'] = eduTime.split('-')[1]
                            eduTemplate['eduSchool'] = edutxtlist[1].get_text()
                            if (len(edutxtlist) >= 4):
                                eduTemplate['education'] = edutxtlist[3].get_text()
                                eduTemplate['eduMaster'] = edutxtlist[2].get_text()
                            else:
                                eduTemplate['education'] = edutxtlist[2].get_text()
                            if (i == len(area) - 1):
                                eduexplist = eduexplist + json.dumps(eduTemplate)
                            else:
                                eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                        except Exception:
                            print('教育经历错误')
                    except Exception:
                        continue
                eduexplist = eduexplist + ']'
            except Exception:
                print("###########学校、专业、学历#############")
            #####最近工作职位####
            try:
                worklist = soup.find_all('tr', style="letter-spacing: 0px;")
                company = worklist[0].find_previous().get_text()
                work = worklist[1].get_text()
                for i in range(0, int(len(worklist) / 2)):
                    try:
                        workTitle = ''
                        workCompany = ''
                        startTime = ''
                        endTime = ''
                        workContent = ''
                        workTemplate = {
                            "startTime": "#STARTTIME#",
                            "endTime": "#ENDTIME#",
                            "workCompany": "#WORKCOMPANY#",
                            "workTitle": "#WORKTITLE#",
                            "workContent": "#WORKCONTENT#"}
                        previouslist = worklist[i * 2].find_all_previous(limit=7)
                        next = worklist[i * 2 + 1].find_next()
                        conent = next.find_next()
                        workContent = conent.get_text()
                        workContent = re.sub('\n', '', workContent)
                        workContent = re.sub('\s', '', workContent)
                        workTime = previouslist[6].get_text()
                        startTime = workTime.split('-')[0]
                        endTime = workTime.split('-')[1]
                        workCompany = worklist[i * 2].find_previous().get_text()
                        workTitle = worklist[i * 2 + 1].get_text()
                        workTitle = re.sub('\n', '', workTitle)
                        workTitle = re.sub('\s', '', workTitle)
                        workTemplate['startTime'] = startTime
                        workTemplate['endTime'] = endTime
                        workTemplate['workTitle'] = workTitle
                        workTemplate['workCompany'] = workCompany
                        workTemplate['workContent'] = workContent
                        if (i == int(len(worklist) / 2) - 1):
                            workexplist = workexplist + json.dumps(workTemplate)
                        else:
                            workexplist = workexplist + json.dumps(workTemplate) + ','
                    except Exception:
                        continue
                workexplist = workexplist + ']'
            except Exception:
                print("###########最近工作职位#############")
        except Exception:
            print("###########提取其他信息错误#############")
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp, company,workexplist,eduexplist]
        people = []
        for each in people1:
            each = re.sub('\n', '', each)
            each = re.sub('\s', '', each)
            each = re.sub('\|', '', each)
            each = re.sub('\t', '', each)
            people.append(each)
        return people
    def zhiliandoc(self,filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company = ''
        time = ''
        workexplist = '['
        eduexplist = '['
        worktag = -1
        edutag = -1
        kschool = []
        ######提取
        try:
            namearea = soup.find('p', style='text-align:left;tab-stops:366.0pt')
            namelist = namearea.select("span")
            name = namelist[0].get_text()
        except Exception:
            print("###########姓名#############")
        basic = soup.find_all('tr', style="mso-yfti-irow:1")
        if(basic!=[] and len(basic)>=2):
            basic1 = basic[1].select('p')
            try:
                basic2 = basic1[0].select('span')[0].get_text()
                basic2str = re.sub('\s', '|', basic2)
                basic2list = basic2str.split('|')
                for each in basic2list:
                    if each in ['男', '女']:
                        sex = each
                    if '岁' in each:
                        age = re.findall('.*?岁', each)[0]
                    if '年工作经验' in each:
                        exp = each
                    if each in ['已婚', '未婚', '离异', '丧偶', '保密']:
                        wed = each
            except Exception:
                print("###########性别、年龄等#############")
            try:
                basic3 = basic1[1].select('span')[0].get_text()
                basic3list = basic3.split('|')
                basic3list2 = basic3list[0].split('：')
                place = basic3list2[1]
            except Exception:
                print("###########place#############")
        workexptxt = []
        worknumber = 0
        eduexptxt = []
        try:
            jobarea = soup.find_all('p', class_="MsoNormal", style="tab-stops:366.0pt")
            for each in jobarea:
                try:
                    job1 = each.select('span')[0].get_text()
                    if '期望工作地区' in job1:
                        job0 = each
                        job2 = job0.find_all_next(limit=5)
                        for k in range(0, len(job2)):
                            job2str = str(job2[k])
                            m = job2str[0] + job2str[1]
                            if m == '<p':
                                job3 = job2[k]
                                city = job3.select('span')[0].get_text()
                    if '期望月薪' in job1:
                        salary0 = each
                        salary2 = salary0.find_all_next(limit=5)
                        for k in range(0, len(salary2)):
                            salary2str = str(salary2[k])
                            m = salary2str[0] + salary2str[1]
                            if m == '<p':
                                salary3 = salary2[k]
                                salary = salary3.select('span')[0].get_text()
                    if '工作经历' in job1:
                        worktag=1
                    if '教育经历' in job1:
                        edutag=1
                    if '手机' in job1:
                        tel0 = each
                        tel2 = tel0.select('span')[0].get_text()
                        tel3 = tel2.split('：')
                        for each in tel3:
                            if re.findall('1\d{10}', each) != []:
                                tel = re.findall('1\d{10}', each)[0]
                            if '@' in each:
                                mail = each
                    if job1 in ['项目经历', '教育经历']:
                        worktag = -1
                    if job1 in ['语言能力', '证书', '培训经历','在校学习情况']:
                        edutag = -1
                    if (worktag == 1 and job1 != ''):
                        workexptxt.append(job1)
                        if (re.match('\d{4}.\d{2} - ', job1)):
                            worknumber = worknumber + 1
                    if (edutag == 1 and job1 != ''):
                        eduexptxt.append(job1)
                except Exception:
                    continue
        except Exception:
            print("###########zhiliandoc手机、邮箱等#############")
        try:
            for i in range(1, len(eduexptxt)):
                try:
                    eduStartTime = ''
                    eduEndTime = ''
                    eduSchool = ''
                    eduMaster = ''
                    eduTemplate = {
                        "eduStart": "",
                        "eduEnd": "",
                        "education": "",
                        "eduSchool": "",
                        "eduMaster": ""}
                    edutex = eduexptxt[i].split('  ')
                    eduTime = re.sub('\s', '', edutex[0])
                    eduStartTime = eduTime.split('-')[0]
                    eduEndTime = eduTime.split('-')[1]
                    eduSchool = re.sub('\s', '', edutex[1])
                    if (len(edutex) > 3):
                        eduMaster = re.sub('\s', '', edutex[2])
                        education = re.sub('\s', '', edutex[3])
                    else:
                        education = re.sub('\s', '', edutex[2])
                    eduTemplate['eduStart'] = eduStartTime
                    eduTemplate['eduEnd'] = eduEndTime
                    eduTemplate['education'] = education
                    eduTemplate['eduSchool'] = eduSchool
                    eduTemplate['eduMaster'] = eduMaster
                    if (i == 1):
                        school = eduSchool
                        master = eduMaster
                        edu = education
                    if (i == len(eduexptxt) - 1):
                        eduexplist = eduexplist + json.dumps(eduTemplate)
                    else:
                        eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                except Exception:
                    continue
        except Exception:
            print("###########智联doc教育经历#############")
        eduexplist=eduexplist + ']'
        j = 0
        try:
            for i in range(1, len(workexptxt)):
                try:
                    if (re.match('\d{4}.\d{2} -', workexptxt[i])):
                        j = j + 1
                        workTitle = ''
                        workCompany = ''
                        startTime = ''
                        endTime = ''
                        workContent = ''
                        workTemplate = {
                            "startTime": "#STARTTIME#",
                            "endTime": "#ENDTIME#",
                            "workCompany": "#WORKCOMPANY#",
                            "workTitle": "#WORKTITLE#",
                            "workContent": "#WORKCONTENT#"}
                        workTime = workexptxt[i].split('  ')[0]
                        startTime = re.sub('\s', '', workTime.split('-')[0])
                        endTime = re.sub('\s', '', workTime.split('-')[1])
                        workCompany = workexptxt[i].split('  ')[1]
                        workTitle1 = workexptxt[i + 1].split('|')
                        workTitle = workTitle1[0]
                        workContent = workexptxt[i + 4]
                        workTemplate['startTime'] = startTime
                        workTemplate['endTime'] = endTime
                        workTemplate['workTitle'] = workTitle
                        workTemplate['workCompany'] = workCompany
                        workTemplate['workContent'] = workContent
                        if (j == 1):
                            work = workTitle
                            company = workCompany
                        if (j == worknumber):
                            workexplist = workexplist + json.dumps(workTemplate)
                        else:
                            workexplist = workexplist + json.dumps(workTemplate) + ','
                except Exception:
                    continue
        except Exception:
            print("###########智联doc工作经历#############")
        workexplist=workexplist + ']'
        people1 = [time,name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for each in people1:
            each = re.sub('\n', '', each)
            each = re.sub('\s', '', each)
            each = re.sub('\|', '', each)
            each = re.sub('\t', '', each)
            people.append(each)
        return people
    def job51(self,filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        time= ''
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company=''
        kage = []
        agetag = -1
        placetag = -1
        edutage = -1
        worktag = -1
        workexplist = '['
        eduexplist = '['
        kplace = []
        ########提取姓名
        try:
            name1 = soup.select('.name')
            name = name1[0].contents[0]
            #####提取手机、邮箱
            basic = soup.find_all('tr', style='height: 28px;')
            try:
                area1 = basic[0].select('td')
                for each in area1:
                    retxt = each.get_text()
                    if re.findall('1\d{10}', retxt) != []:
                        tel = re.findall('1\d{10}', retxt)[0]
                    if re.findall('@', retxt) != []:
                        mail = retxt
            except Exception:
                print("###########place#############")
            #####提取性别、年龄、工作经验、所在地
            try:
                info = basic[1].contents[0].contents
                for each in info:
                    if each in ['男', '女']:
                        sex = each
                    if '岁' in each:
                        age1 = each
                    if '现居住' in each:
                        place1 = each
                    if '年工作经验' in each or '无工作经验' in each:
                        exp = each
                for i in range(0, len(age1)):
                    if '岁' == age1[i]:
                        agetag = i
                for i in range(0, agetag + 1):
                    kage.append(age1[i])
                age = ''.join(kage)
                for i in range(0, len(place1)):
                    if '住' in place1[i]:
                        placetag = i
                for i in range(placetag + 1, len(place1)):
                    kplace.append(place1[i])
                place = ''.join(kplace)
            except Exception:
                print("###########tel、mail#############")
            #####提取最近工作、专业、学校、学历
            workarea = soup.select('td .keys')
            for each in workarea:
                if each.string == '职　位：':
                    work1 = each
                    work = work1.find_next().string
                if each.string == '公　司：':
                    company1 = each
                    company = company1.find_next().string
                if each.string == '婚姻状况：':
                    wed1 = each
                    wed = wed1.find_next().string
                if each.string == '期望薪资：':
                    salary1 = each
                    salary = salary1.find_next().string
                if each.string == '地点：':
                    city1 = each
                    city = city1.find_next().string
                if each.string == '专　业：':
                    master1 = each
                    master = master1.find_next().string
                if each.string == '学　校：':
                    school1 = each
                    school = school1.find_next().string
                if each.string == '学历/学位：':
                    edu1 = each
                    edu = edu1.find_next().string
            #####找更新时间
            try:
                time = soup.find_all('span', style="color:#256fb8;")[3].get_text()
            except Exception:
                print("###########place#############")
            try:
                area = soup.find_all('table', cellspacing="0", cellpadding="0", class_="box")
                for i in range(0, len(area)):
                    results = area[i].find_all('td' ,class_="plate1")
                    for every in results:
                        if '工作经验' == every.string:
                            worktag = i
                        if '教育经历' == every.string:
                            edutag = i
                if worktag != -1:
                    try:
                        worktime=area[worktag].find_all('td',class_="time")
                        timelist=[]
                        for eachtime in worktime:
                            try:
                                if re.match('\d{4}/\d{1}', eachtime.string):
                                    timelist.append(eachtime.string)
                            except Exception:
                                continue
                        contentList = area[worktag].find_all('td', class_="txt1")
                        companyList = area[worktag].find_all('span', class_="bold")
                        worklist=area[worktag].find_all('strong',class_="txt3")
                        for i in range(0, len(worklist)):
                            try:
                                workTitle = ''
                                workCompany = ''
                                startTime = ''
                                endTime = ''
                                workContent = ''
                                workTemplate = {
                                    "startTime": "#STARTTIME#",
                                    "endTime": "#ENDTIME#",
                                    "workCompany": "#WORKCOMPANY#",
                                    "workTitle": "#WORKTITLE#",
                                    "workContent": "#WORKCONTENT#"}
                                workTitle = worklist[i].get_text()
                                workTime = timelist[i]
                                startTime = re.sub('\s', '', workTime.split('-')[0])
                                endTime = re.sub('\s', '', workTime.split('-')[1])
                                workContent=contentList[i].get_text()
                                workCompany =companyList[i*2].get_text()
                                workTemplate['startTime'] = startTime
                                workTemplate['endTime'] = endTime
                                workTemplate['workTitle'] = workTitle
                                workTemplate['workCompany'] = workCompany
                                workTemplate['workContent'] = workContent
                                if(i==0):
                                    work=workTitle
                                    company=workCompany
                                if (i == len(worklist)-1):
                                    workexplist = workexplist + json.dumps(workTemplate)
                                else:
                                    workexplist = workexplist + json.dumps(workTemplate) + ','
                            except Exception:
                                continue
                    except Exception:
                        print("###########51job1工作经历#############")
                if edutag != -1:
                    try:
                        edutime = area[edutag].find_all('td', class_="time")
                        edutimelist = []
                        for eachtime in edutime:
                            try:
                                if re.match('\d{4}/\d{1}', eachtime.string):
                                    edutimelist.append(eachtime.string)
                            except Exception:
                                continue
                        masterList = area[edutag].find_all('td', class_="txt1")
                        edulist = area[edutag].find_all('strong', class_="txt3")
                        for i in range(0, len(edulist)):
                            try:
                                eduStartTime = ''
                                eduEndTime = ''
                                eduSchool = ''
                                eduMaster = ''
                                education = ''
                                eduTemplate = {
                                    "eduStart": "",
                                    "eduEnd": "",
                                    "education": "",
                                    "eduSchool": "",
                                    "eduMaster": ""}
                                try:
                                    eduTime = edutimelist[i]
                                    eduStartTime = eduTime.split('-')[0]
                                    eduEndTime = eduTime.split('-')[1]
                                except Exception:
                                    print("edutime error")
                                try:
                                    eduSchool = edulist[i].get_text()
                                    eduMaster = masterList[i].get_text().split('|')[1]
                                    education = masterList[i].get_text().split('|')[0]
                                except Exception:
                                    print("eduMaster error")
                                eduTemplate['eduStart'] = eduStartTime
                                eduTemplate['eduEnd'] = eduEndTime
                                eduTemplate['education'] = education
                                eduTemplate['eduSchool'] = eduSchool
                                eduTemplate['eduMaster'] = eduMaster
                                if (i == 0):
                                    school = eduSchool
                                    master = eduMaster
                                if (i == len(edulist) - 1):
                                    eduexplist = eduexplist + json.dumps(eduTemplate)
                                else:
                                    eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                            except Exception:
                                continue
                    except Exception:
                        print("###########51job1教育经历#############")
            except Exception:
                print("学校、专业、最近工作职位错误")
        except Exception:
            try:
                try:
                    nametext = soup.find('span', style="color:#333333")
                    name = txt_wrap_by('<span style="color:#333333">', '</span>', str(nametext))
                except Exception:
                    print("###########提取姓名错误#############")
                try:
                    basiclist = soup.find_all('td', style="padding:0 25px;line-height:30px;")
                    for i in range(0, len(basiclist)):
                        tellist = basiclist[i].select('td')
                        for k in range(0, len(tellist)):
                            temp = txt_wrap_by("<td>", "</td>", str(tellist[k]))
                            if (temp != None and re.findall('1\d{10}', temp) != []):
                                tel = temp
                            elif (temp != None and re.findall('@', temp) != []):
                                mail = temp
                        sexAge = basiclist[i].select('p')
                        for k in range(0, len(sexAge)):
                            temp = txt_wrap_by("<p>", "</p>", str(sexAge[k]))
                            sexAgelist = temp.split('<span class="p5"> | </span>')
                            for each in sexAgelist:
                                if each in ['男', '女']:
                                    sex = each
                                if '岁' in each:
                                    age = each
                                if '现居住' in each:
                                    place = re.sub('现居住', '', each)
                                if '年工作经验' in each or '无工作经验' in each:
                                    exp = each
                except Exception:
                    print("###########提取姓别等错误#############")
                edubasic2 = soup.find_all('td', class_='keys')
                for k in range(0, len(edubasic2)):
                    try:
                        if ('专业：' == edubasic2[k].string):
                            master = edubasic2[k].find_next().string
                        if ('学校：' == edubasic2[k].string):
                            school = edubasic2[k].find_next().string
                        if ('学历/学位：'== edubasic2[k].string):
                            edu = edubasic2[k].find_next().string
                        if ('婚姻状况：'== edubasic2[k].string):
                            wed = edubasic2[k].find_next().string
                        if ('期望薪资：'== edubasic2[k].string):
                            salary = edubasic2[k].find_next().string
                        if ('职位：' == edubasic2[k].string):
                            work = edubasic2[k].find_next().string
                        if ('公司：' == edubasic2[k].string):
                            company = edubasic2[k].find_next().string
                        if ('地点' in str(edubasic2[k])):
                            city = re.sub('<td class="txt2" valign="top">', '', str(edubasic2[k].find_next()))
                            city = re.sub('<span class="tag">', '', city)
                            city = re.sub('</td>', '', city)
                            city = re.sub('</span>', '', city)
                    except Exception:
                        continue
                try:
                    area = soup.find_all('table', class_="box")
                    for i in range(0, len(area)):
                        results = area[i].find_all('td', class_="plate1")
                        for every in results:
                            if '工作经验' == every.string:
                                worktag = i
                            if '教育经历' == every.string:
                                edutag = i
                    if worktag != -1:
                        try:
                            worktime = area[worktag].find_all('td', class_="times")
                            timelist = []
                            for eachtime in worktime:
                                try:
                                    if re.match('\d{4}/\d{1}', eachtime.string):
                                        timelist.append(eachtime.string)
                                except Exception:
                                    continue
                            contentList = area[worktag].find_all('td', class_="txt1")
                            companyList = area[worktag].find_all('td', class_="phd tb1")
                            worklist = area[worktag].find_all('strong', class_="txt3")
                            for i in range(0, len(worklist)):
                                try:
                                    workTitle = ''
                                    workCompany = ''
                                    startTime = ''
                                    endTime = ''
                                    workContent = ''
                                    workTemplate = {
                                        "startTime": "#STARTTIME#",
                                        "endTime": "#ENDTIME#",
                                        "workCompany": "#WORKCOMPANY#",
                                        "workTitle": "#WORKTITLE#",
                                        "workContent": "#WORKCONTENT#"}
                                    workTitle = worklist[i].get_text()
                                    workTime = timelist[i]
                                    startTime = re.sub('\s', '', workTime.split('-')[0])
                                    endTime = re.sub('\s', '', workTime.split('-')[1])
                                    workContent = contentList[i].get_text()
                                    workCompany = companyList[i].get_text()
                                    workTemplate['startTime'] = startTime
                                    workTemplate['endTime'] = endTime
                                    workTemplate['workTitle'] = workTitle
                                    workTemplate['workCompany'] = workCompany
                                    workTemplate['workContent'] = workContent
                                    if (i == 0):
                                        work = workTitle
                                        company = workCompany
                                    if (i == len(worklist) - 1):
                                        workexplist = workexplist + json.dumps(workTemplate)
                                    else:
                                        workexplist = workexplist + json.dumps(workTemplate) + ','
                                except Exception:
                                    continue
                        except Exception:
                            print("###########51job2工作经历#############")
                    if edutag != -1:
                        try:
                            edutimelist = area[edutag].find_all('td', class_="times")
                            masterList = area[edutag].find_all('td', class_="tb1")
                            edulist = area[edutag].find_all('td', class_="rtbox")
                            for i in range(0, len(edulist)):
                                try:
                                    eduStartTime = ''
                                    eduEndTime = ''
                                    eduSchool = ''
                                    eduMaster = ''
                                    education = ''
                                    eduTemplate = {
                                        "eduStart": "",
                                        "eduEnd": "",
                                        "education": "",
                                        "eduSchool": "",
                                        "eduMaster": ""}
                                    try:
                                        eduTime = edutimelist[i].get_text()
                                        eduStartTime = re.sub('\s', '', eduTime.split('-')[0])
                                        eduEndTime = re.sub('\s', '', eduTime.split('-')[1])
                                    except Exception:
                                        print("edutime error")
                                    try:
                                        eduSchool = edulist[i].get_text()
                                        masticBasic=masterList[i*2].get_text()
                                        eduMaster =masticBasic.split('|')[1]
                                        education = masticBasic.split('|')[0]
                                    except Exception:
                                        print("eduMaster error")
                                    eduTemplate['eduStart'] = eduStartTime
                                    eduTemplate['eduEnd'] = eduEndTime
                                    eduTemplate['education'] = education
                                    eduTemplate['eduSchool'] = eduSchool
                                    eduTemplate['eduMaster'] = eduMaster
                                    if (i == 0):
                                        school = eduSchool
                                        master = eduMaster
                                    if (i == len(edulist) - 1):
                                        eduexplist = eduexplist + json.dumps(eduTemplate)
                                    else:
                                        eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                                except Exception:
                                    continue
                        except Exception:
                            print("###########51job2教育经历#############")
                except Exception:
                    print("##########51job2工作、教育经历##############")
            except Exception:
                return []
        eduexplist = eduexplist + ']'
        workexplist = workexplist + ']'
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for message in people1:
            if (message != None):
                message = re.sub('\n', '', message)
                message = re.sub('\s', '', message)
                message = re.sub('\r', '', message)
                message = re.sub('\|', '', message)
            else:
                message = ''
            people.append(message)
        return people

    def jianlika(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        time = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company = ''
        workexplist='['
        eduexplist='['
        worktag=-1
        edutag=-1
        #############
        basic = soup.find_all('font')
        for k in range(0, len(basic)):
            bgettext = basic[k].get_text()
            bgettext = re.sub('\xa0', '', bgettext)
            if '姓名' in bgettext:
                name2 = bgettext.split('：')
                if len(name2) > 1:
                    name = name2[1]
            if '电话' in bgettext:
                tel2 = bgettext.split('：')
                if len(tel2) > 1:
                    tel = tel2[1]
            if '邮箱' in bgettext:
                mail2 = bgettext.split('：')
                if len(mail2) > 1:
                    mail = mail2[1]
            if '更新时间' in bgettext:
                time2 = bgettext.split(':')
                if len(time2) > 1:
                    time = time2[1]
        workexptxt=[]
        worknumber=0
        eduexptxt=[]
        workarea = soup.select('p')
        for each in workarea:
            try:
                egettextsrc = each.get_text()
                egettext = re.sub('\xa0', '', egettextsrc)
                if '期望地点' in egettext:
                    ltt = egettext.split('：')
                    if len(ltt) > 1:
                        city = ltt[1]
                if '期望月薪' in egettext:
                    ltt1 = egettext.split('：')
                    if len(ltt1) > 1:
                        salary = ltt1[1]
                if ('女' in egettext or '男' in egettext) and '|' in egettext:
                    info1 = egettext.split('|')
                    for ea in info1:
                        if ea in ['已婚', '未婚', '离异', '丧偶', '保密']:
                            wed = ea
                        if ea in ['男', '女']:
                            sex = ea
                        if '工作经验' in ea:
                            exp = ea
                        if '最高学历' in ea:
                            edu1 = ea.split('：')
                            if len(edu1) > 1:
                                edu = edu1[1]
                        if re.findall('\d{2}', ea) != [] and '工作经验' not in ea:
                            age = re.findall('\d{2}', ea)[0]
                if '所在地' in egettext:
                    place2 = egettext.split('：')
                    if len(place2) > 1:
                        place = place2[1]
                        if '户口' in place:
                            placelist = place.split('户口')
                            place = placelist[0]
                if '教育经历' in egettext:
                    edutag=1
                if '工作经历' in egettext:
                    worktag = 1
                if egettext in [ '项目经历','教育经历'] :
                    worktag=-1
                if egettext in [ '语言能力','证书','培训经历']:
                    edutag=-1
                if(worktag==1 and egettextsrc!=''):
                    workexptxt.append(egettextsrc)
                    if (re.match('\d{4}.\d{2}-', egettext)):
                        worknumber=worknumber+1
                if (edutag == 1 and egettextsrc!=''):
                    eduexptxt.append(egettextsrc)
            except Exception:
                continue
        try:
            for i in range(1, len(eduexptxt)):
                try:
                    eduStartTime = ''
                    eduEndTime = ''
                    eduSchool = ''
                    eduMaster = ''
                    eduTemplate = {
                        "eduStart": "",
                        "eduEnd": "",
                        "education": "",
                        "eduSchool": "",
                        "eduMaster": ""}
                    edutex = eduexptxt[i].split('\xa0')
                    eduStartTime = edutex[0].split('-')[0]
                    eduEndTime = edutex[0].split('-')[1]
                    eduSchool = edutex[1]
                    education = edutex[2]
                    if (len(edutex) > 3):
                        eduMaster = edutex[3]
                    eduTemplate['eduStart'] = eduStartTime
                    eduTemplate['eduEnd'] = eduEndTime
                    eduTemplate['education'] = education
                    eduTemplate['eduSchool'] = eduSchool
                    eduTemplate['eduMaster'] = eduMaster
                    if (i == 1):
                        school = eduSchool
                        master = eduMaster
                    if (i == len(eduexptxt) - 1):
                        eduexplist = eduexplist + json.dumps(eduTemplate)
                    else:
                        eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                except Exception:
                    continue
        except Exception:
            print("###########jinalika教育经历#############")
        eduexplist=eduexplist+ ']'
        j = 0
        for i in range(1,len(workexptxt)):
            try:
                if (re.match('\d{4}.\d{2}-', workexptxt[i])):
                    j = j + 1
                    workTitle = ''
                    workCompany = ''
                    startTime = ''
                    endTime = ''
                    workContent = ''
                    workTemplate = {
                        "startTime": "#STARTTIME#",
                        "endTime": "#ENDTIME#",
                        "workCompany": "#WORKCOMPANY#",
                        "workTitle": "#WORKTITLE#",
                        "workContent": "#WORKCONTENT#"}
                    workTime = workexptxt[i].split(' ')[0]
                    startTime = workTime.split('-')[0]
                    endTime = workTime.split('-')[1]
                    workCompany = workexptxt[i].split(' ')[1]
                    workTitle1 = workexptxt[i + 1].split('\xa0\xa0')
                    workTitle = workTitle1[len(workTitle1) - 1]
                    workContent = workexptxt[i + 3]
                    workTemplate['startTime'] = startTime
                    workTemplate['endTime'] = endTime
                    workTemplate['workTitle'] = workTitle
                    workTemplate['workCompany'] = workCompany
                    workTemplate['workContent'] = workContent
                    if (j == 1):
                        work = workTitle
                        company = workCompany
                    if (j == worknumber):
                        workexplist = workexplist + json.dumps(workTemplate)
                    else:
                        workexplist = workexplist + json.dumps(workTemplate) + ','
            except Exception:
                continue
        workexplist=workexplist + ']'
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for each in people1:
            each = re.sub('\n', '', each)
            each = re.sub('\s', '', each)
            each = re.sub('\|', '', each)
            each = re.sub('\t', '', each)
            people.append(each)
        print(people)
        return people
    def zhuopin(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区
        name = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        worktag = -1
        edutag = -1
        work = ''
        time =''
        company = ''
        eduexplist = '[]'
        workexplist = '[]'
        people = []
        try:
            ####姓名、性别、工作经验、学历
            name2 = soup.find_all('span', style="font-family:宋体; font-size:12pt")
            for i in range(len(name2)):
                try:
                    if ('姓名：' in name2[i].get_text()):
                        name = name2[i].get_text().split('：')[1]
                        if (name == ''):
                            name = name2[i + 1].get_text()
                    if ('性别：' in name2[i].get_text()):
                        sex = name2[i].get_text().split('：')[1]
                    if ('工作年限：' in name2[i].get_text()):
                        exp = name2[i].get_text().split('：')[1]
                    if ('学历：' in name2[i].get_text()):
                        edu = name2[i].get_text().split('：')[1]
                    if ('年龄：' in name2[i].get_text()):
                        age = name2[i].get_text().split('：')[1]
                    #####提取手机和邮箱
                    if ('联系电话：' in name2[i].get_text()):
                        temp = name2[i + 1].get_text()
                        if (' ' in temp):
                            temp = temp.replace(' ', '')
                        if re.match('^1\d{10}', temp):
                            tel = name2[i + 1].get_text()
                        else:
                            tel = name2[i + 1].get_text() + name2[i + 2].get_text()
                            if ('婚姻状况：' in name2[i + 2].get_text()):
                                tel = ''
                    if ('@' in name2[i].get_text()):
                        mail = name2[i].get_text()
                except Exception:
                    continue
            try:
                ##########年龄、婚姻、所在地
                detail = soup.find('li', class_='gray-line')
                detailstr = detail.get_text()
                detaillist = detailstr.split('|')
                wed = detaillist[2]
                place = detaillist[3]
                #########提取最近一份工作职位和学校、专业
                area = soup.find_all('div', class_='detail-mar')
                for i in range(0, len(area)):
                    results = area[i].select('.common-title-new')
                    for every in results:
                        if '工作经验' == every.string:
                            worktag = i
                        if '教育背景' == every.string:
                            edutag = i
                if worktag != -1:
                    wtitle = area[worktag].select('.sub-title-bg')
                    workspan = wtitle[0].select('span')
                    work = workspan[2].string
                if edutag != -1:
                    etitle = area[edutag].select('.sub-title-bg')
                    school = etitle[0].contents[2]
                    mtitle = area[edutag].select('.detail-cons2')
                    master = mtitle[0].select('em')[0].string
                #########提取期望工作地点和期望薪资
                expect = soup.find_all('div', class_='new-border-bottom')
                expect1 = expect[2]
                expect2 = expect1.select('.detail-cons')
                city = expect2[2].string
                salary = expect2[3].string
            except Exception:
                print("###########提取其他信息错误#############")
            # ['文件名','姓名','性别','年龄','手机号','邮箱','学历','婚姻','所在地','学校','专业','期望工作地点','期望薪资','工作年限'])
            people1 = [time,name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
            for each in people1:
                each = re.sub('\n', '', each)
                each = re.sub('\s', '', each)
                each = re.sub('\|', '', each)
                people.append(each)
        except Exception:
            return []
        return people
    def zhilianhtm(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        time = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company = ''
        eduexplist = '['
        workexplist = '['
        people = []
        try:
            try:
                time = soup.find('strong', id='resumeUpdateTime').string
                name = soup.find('div', id="userName").string
            except Exception:
                print("###########name、time错误#############")
            try:
                basic = soup.find_all('div', class_="summary-top")
                basicstr = basic[0].select('span')[0].get_text()
                basic2str = re.sub('\s\s\s\s', '|', basicstr)
                basiclist = basic2str.split('|')
                for each in basiclist:
                    if each in ['男', '女']:
                        sex = each
                    if '岁' in each:
                        age = re.findall('.*?岁', each)[0]
                    if '年工作经验' in each:
                        exp = each
                    if each in ['已婚', '未婚', '离异', '丧偶', '保密']:
                        wed = each
                    if each in ['本科', '硕士', '博士', '专科','大专', '高中', '初中', '小学']:
                        edu = each
            except Exception:
                print("###########name、time错误#############")
            try:
                mail = soup.find('i', class_="mail").get_text()
                telbasic = soup.find_all('div', class_="feedbackD")
                tel = telbasic[0].select('b')[0].get_text()
            except Exception:
                print("###########提取mail、tel错误#############")
            #########学校、专业
            try:
                explist = soup.find_all('div', class_="resume-preview-top")
                explist1 = explist[0].select('td')
                for i in range(0, len(explist1)):
                    if ('期望工作地区：' in explist1[i].get_text()):
                        city = explist1[i + 1].get_text()
                    if ('期望月薪' in explist1[i].get_text()):
                        salary = explist1[i + 1].get_text()
            except Exception:
                print("###########期望信息错误#############")
            try:
                area = soup.find_all('div', class_="resume-preview-dl educationContent")
                eduarea = area[0].get_text().split('\n')
                edutxtlist = []
                for k in range (0,len(eduarea)):
                    if eduarea[k]!='':
                        edutxtlist.append(eduarea[k])
                for i in range(0, len(edutxtlist)):
                    try:
                        eduStartTime = ''
                        eduEndTime = ''
                        eduSchool = ''
                        eduMaster = ''
                        eduTemplate = {
                            "eduStart": "",
                            "eduEnd": "",
                            "education": "",
                            "eduSchool": "",
                            "eduMaster": ""}
                        area1 = re.sub('\s\s', '|', edutxtlist[i])
                        arealist = area1.split('|')
                        eduTime =arealist[0]
                        eduStartTime = eduTime.split(' - ')[0]
                        eduEndTime = eduTime.split(' - ')[1]
                        eduSchool =  arealist[1]
                        eduMaster = arealist[2]
                        education = arealist[3]
                        eduTemplate['eduStart'] = eduStartTime
                        eduTemplate['eduEnd'] = eduEndTime
                        eduTemplate['education'] = education
                        eduTemplate['eduSchool'] = eduSchool
                        eduTemplate['eduMaster'] = eduMaster
                        if(i==0):
                            school = arealist[1]
                            master = arealist[2]
                        if (i == len(edutxtlist) - 1):
                            eduexplist = eduexplist + json.dumps(eduTemplate)
                        else:
                            eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########智联html教育经历#############")
            eduexplist = eduexplist + ']'
            try:
                worklist = soup.find_all('div', class_="resume-preview-all workExperience")
                workbase = worklist[0].select('h2')
                for i in range(0, len(workbase)):
                    try:
                        workTitle = ''
                        workCompany = ''
                        startTime = ''
                        endTime = ''
                        workContent = ''
                        workTemplate = {
                            "startTime": "#STARTTIME#",
                            "endTime": "#ENDTIME#",
                            "workCompany": "#WORKCOMPANY#",
                            "workTitle": "#WORKTITLE#",
                            "workContent": "#WORKCONTENT#"}
                        work1 = workbase[i].get_text()
                        work1 = re.sub('\s\s', '|', work1)
                        worktxtlist=work1.split('|')
                        workTime = worktxtlist[0]
                        startTime = re.sub('\s', '', workTime.split('-')[0])
                        endTime = re.sub('\s', '', workTime.split('-')[1])
                        workCompany = worktxtlist[1]
                        workTitle1 = worklist[0].select('h5')[i].get_text()
                        workTitle = workTitle1.split('|')[0]
                        workContent = worklist[0].select('td')[i*2+1].get_text()
                        workTemplate['startTime'] = startTime
                        workTemplate['endTime'] = endTime
                        workTemplate['workTitle'] = workTitle
                        workTemplate['workCompany'] = workCompany
                        workTemplate['workContent'] = workContent
                        if(i==0):
                            work = workTitle
                            company = workCompany
                        if (i == len(workbase)-1):
                            workexplist = workexplist + json.dumps(workTemplate)
                        else:
                            workexplist = workexplist + json.dumps(workTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########智联html工作经历#############")
            workexplist = workexplist + ']'
            # ['文件名','更新时间','姓名','性别','年龄','手机号','邮箱','学历','婚姻','所在地','学校','专业','最近工作职位','期望工作地点','期望薪资','工作年限'])
            people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary,
                       exp,company,workexplist,eduexplist]
            for each in people1:
                if (each != None):
                    each = re.sub('\n', '', each)
                    each = re.sub('\s', '', each)
                    each = re.sub('\|', '', each)
                else:
                    each = ''
                people.append(each)
        except Exception:
            return []
        return people
    def zhuopinhtm(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        time = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company=''
        eduexplist = '['
        workexplist = '['
        people = []
        try:
            #################姓名、性别、工作经验、学历
            name = soup.find('span', id='namespan').string
            basic = soup.find('li', class_='d-name')
            basicstr = basic.get_text()
            basiclist = basicstr.split('|')
            for each in basiclist:
                if each in ['男', '女']:
                    sex = each
                if '工作经验' in each:
                    exp = each
                if each in ['本科', '硕士', '博士','大专', '专科', '高中', '初中', '小学']:
                    edu = each
            #####提取手机和邮箱
            tel = soup.select('#mobile')[0].string
            mail = soup.select('#email')[0].select('a')[0].string
            try:
                ##########年龄、所在地
                detail = soup.find('li', class_='gray-line')
                detailstr = detail.get_text()
                detaillist = detailstr.split('|')
                for each in detaillist:
                    if '岁' in each:
                        age = re.findall('.*?岁', each)[0]
                    if each in ['已婚', '未婚', '离异', '丧偶', '保密']:
                        wed = each
                place = detaillist[len(detaillist)-1]
                timetail = soup.find('span', class_='update').get_text()
                timetail = re.sub('\n', '', timetail)
                timetail = re.sub('\s', '', timetail)
                if (timetail != '' and "：" in timetail):
                    timelist = timetail.split('：')
                    time = timelist[1]
            except Exception:
                print("###########提取其他信息错误#############")
            try:
                #########提取期望工作地点和期望薪资
                expect = soup.find_all('div', class_='new-border-bottom')
                expect1 = expect[2]
                expect2 = expect1.find_all('div', class_='detail-lists clearfix')
                for i in range(0, len(expect2)):
                    if ('期望工作地点：' in expect2[i].get_text()):
                        expectcity = expect2[i].select('.detail-cons')
                        city = expectcity[0].string
                    if ('期望薪资' in expect2[i].get_text()):
                        expectsalary = expect2[i].select('.detail-cons')
                        salary = expectsalary[0].string
            except Exception:
                print("期望工作地点和期望薪资错误")
            try:
                area = soup.find_all('div', class_='detail-mar')
                for i in range(0, len(area)):
                    results = area[i].select('.common-title-new')
                    for every in results:
                        if '工作经验' == every.string:
                            worktag = i
                        if '教育背景' == every.string:
                            edutag = i
                if worktag != -1:
                    try:
                        worklist=area[worktag].select('h5')
                        for i in range(0, len(worklist)):
                            try:
                                workTitle = ''
                                workCompany = ''
                                startTime = ''
                                endTime = ''
                                workContent = ''
                                workTemplate = {
                                    "startTime": "#STARTTIME#",
                                    "endTime": "#ENDTIME#",
                                    "workCompany": "#WORKCOMPANY#",
                                    "workTitle": "#WORKTITLE#",
                                    "workContent": "#WORKCONTENT#"}
                                workbasiclist=worklist[i].select('span')
                                if(len(workbasiclist)>=3):
                                    workTime = workbasiclist[0].get_text()
                                    startTime = re.sub('\s', '', workTime.split('--')[0])
                                    endTime = re.sub('\s', '', workTime.split('--')[1])
                                    workCompany = workbasiclist[1].get_text()
                                    workTitle = workbasiclist[2].get_text()
                                    workTitle = re.sub('\s', '', workTitle)
                                workTemplate['startTime'] = startTime
                                workTemplate['endTime'] = endTime
                                workTemplate['workTitle'] = workTitle
                                workTemplate['workCompany'] = workCompany
                                workTemplate['workContent'] = workContent
                                if(i==0):
                                    work=workTitle
                                    company=workCompany
                                if (i == len(worklist)-1):
                                    workexplist = workexplist + json.dumps(workTemplate)
                                else:
                                    workexplist = workexplist + json.dumps(workTemplate) + ','
                            except Exception:
                                continue
                    except Exception:
                        print("###########猎聘1工作经历#############")
                if edutag != -1:
                    try:
                        edulist = area[edutag].select('h5')
                        for i in range(0, len(edulist)):
                            try:
                                eduStartTime = ''
                                eduEndTime = ''
                                eduSchool = ''
                                eduMaster = ''
                                eduTemplate = {
                                    "eduStart": "",
                                    "eduEnd": "",
                                    "education": "",
                                    "eduSchool": "",
                                    "eduMaster": ""}
                                edubasic= re.sub('\s','', edulist[i].get_text())
                                if('--至今' in edubasic):
                                    eduEndTime='至今'
                                    eduStartTime=edubasic.split('--至今')[0]
                                    eduSchool=edubasic.split('--至今')[1]
                                else:
                                    edubasic = re.sub('--', '', edubasic)
                                    edubasiclist = edubasic.split('月')
                                    eduStartTime = edubasiclist[0]
                                    eduEndTime = edubasiclist[1]
                                    eduSchool = edubasiclist[2]
                                mtitleMaster= area[edutag].select('.detail-cons2')
                                eduMaster=mtitleMaster[i*2].string
                                education = mtitleMaster[i*2+1].find('span').get_text()
                                eduTemplate['eduStart'] = eduStartTime
                                eduTemplate['eduEnd'] = eduEndTime
                                eduTemplate['education'] = education
                                eduTemplate['eduSchool'] = eduSchool
                                eduTemplate['eduMaster'] = eduMaster
                                if (i == 0):
                                    school = eduSchool
                                    master = eduMaster
                                if (i == len(edulist) - 1):
                                    eduexplist = eduexplist + json.dumps(eduTemplate)
                                else:
                                    eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                            except Exception:
                                continue
                    except Exception:
                        print("###########卓聘html教育经历#############")
            except Exception:
                print("学校、专业、最近工作职位错误")
            eduexplist = eduexplist + ']'
            workexplist = workexplist + ']'
            # ['文件名','更新时间','姓名','性别','年龄','手机号','邮箱','学历','婚姻','所在地','学校','专业','最近工作职位','期望工作地点','期望薪资','工作年限'])
            people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary,exp,company,workexplist,eduexplist]
            for each in people1:
                if(each!=None):
                    each = re.sub('\n', '', each)
                    each = re.sub('\s', '', each)
                    each = re.sub('\|', '', each)
                else:
                    each=''
                people.append(each)
        except Exception:
            return []
        return people
    def liepin(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        time = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        company = ''
        work = ''
        worktag=-1
        edutag=-1
        workexplist='['
        eduexplist='['
        people = []
        try:
            name = soup.find('b', style='mso-bidi-font-weight:normal').get_text()
            try:
                sex = soup.find('span',
                                style='font-family:宋体;mso-ascii-font-family:Tahoma;mso-hansi-font-family:Tahoma').get_text()
                work = soup.find('span', class_="GramE").get_text()
            except Exception:
                print("liepin提取姓名性别上一份工作错误")
            workexptxt = []
            worknumber = 0
            edunumber = 0
            eduexptxt = []
            try:
                basic = soup.find_all('p', class_="MsoNormal")
                for i in range(0, len(basic)):
                    result = basic[i].get_text()
                    result = re.sub('\n', '', result)
                    result = re.sub('\s', '', result)
                    result = re.sub('\r', '', result)
                    if '工作年限：' in result:
                        exp = basic[i + 1].get_text()
                    if '年龄：' in result:
                        age = basic[i + 1].get_text()
                    if '婚姻状况：' in result:
                        wed = basic[i + 1].get_text()
                    if '手机：' in result:
                        tel = basic[i + 1].get_text()
                    if '邮箱：' in result:
                        mail = basic[i + 1].get_text()
                    if '期望地点：' in result:
                        city = basic[i + 1].get_text()
                    if '所在地点：' in result:
                        place = basic[i + 1].get_text()
                    if '期望年薪：' in result:
                        salary = basic[i + 1].get_text()
                    if '学历：' in result:
                        edu = basic[i + 1].get_text()
                    if '专业名称：' in result:
                        master = basic[i + 1].get_text()
                    if '教育经历' == result:
                        edutag=1
                        school = basic[i + 1].get_text()
                    if '工作经历' == result:
                        worktag=1
                        company = basic[i + 2].get_text()
                    if '期望年薪：' in result and salary=='':
                        salary = basic[i + 1].get_text()
                    if result in ['项目经历', '教育经历']:
                        worktag = -1
                    if result in ['语言能力', '证书', '培训经历', '附加信息']:
                        edutag = -1
                    if (worktag == 1 and result != ''):
                        workexptxt.append(result)
                        if ('公司描述：'==result):
                            worknumber = worknumber + 1
                    if (edutag == 1 and result != ''):
                        eduexptxt.append(result)
                        if ('学历：'==result):
                            edunumber = edunumber + 1
            except Exception:
                print("liepin提取其他信息错误")
            try:
                for i in range(0, edunumber):
                    try:
                        eduStartTime = ''
                        eduEndTime = ''
                        eduSchool = ''
                        eduMaster = ''
                        eduTemplate = {
                            "eduStart": "",
                            "eduEnd": "",
                            "education": "",
                            "eduSchool": "",
                            "eduMaster": ""}
                        edutex = eduexptxt[i*7+1].split('（')
                        eduTime = re.sub('）', '', edutex[1])
                        eduStartTime = eduTime.split('-')[0]
                        eduEndTime = eduTime.split('-')[1]
                        eduSchool = edutex[0]
                        eduMaster = eduexptxt[i*7+3]
                        education = eduexptxt[i*7+5]
                        eduTemplate['eduStart'] = eduStartTime
                        eduTemplate['eduEnd'] = eduEndTime
                        eduTemplate['education'] = education
                        eduTemplate['eduSchool'] = eduSchool
                        eduTemplate['eduMaster'] = eduMaster
                        if (i == edunumber - 1):
                            eduexplist = eduexplist + json.dumps(eduTemplate)
                        else:
                            eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########猎聘1教育经历#############")
            eduexplist = eduexplist + ']'
            try:
                for i in range(0, worknumber):
                    try:
                        workTitle = ''
                        workCompany = ''
                        startTime = ''
                        endTime = ''
                        workContent = ''
                        workTemplate = {
                            "startTime": "#STARTTIME#",
                            "endTime": "#ENDTIME#",
                            "workCompany": "#WORKCOMPANY#",
                            "workTitle": "#WORKTITLE#",
                            "workContent": "#WORKCONTENT#"}
                        workTime = workexptxt[i*22+1]
                        startTime = re.sub('\s', '', workTime.split('-')[0])
                        endTime = re.sub('\s', '', workTime.split('-')[1])
                        workCompany = workexptxt[i*22+2]
                        workTitle = workexptxt[i*22 + 11]
                        workContent = workexptxt[i*22 + 22]
                        workTemplate['startTime'] = startTime
                        workTemplate['endTime'] = endTime
                        workTemplate['workTitle'] = workTitle
                        workTemplate['workCompany'] = workCompany
                        workTemplate['workContent'] = workContent
                        if (i == worknumber-1):
                            workexplist = workexplist + json.dumps(workTemplate)
                        else:
                            workexplist = workexplist + json.dumps(workTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########猎聘1工作经历#############")
            workexplist = workexplist + ']'
        except Exception:
            try:
                workexptxt = []
                eduexptxt = []
                worknumber = 0
                edunumber = 0
                basiclist = soup.find_all('table')
                for each in basiclist:
                    eachlist = each.select('p')
                    for i in range(0, len(eachlist)):
                        try:
                            result = eachlist[i].get_text()
                            result = re.sub('\n', '', result)
                            result = re.sub('\r', '', result)
                            job1  = re.sub('\s', '', result)
                            if '工作年限：' in result or 'Service Year：' in result:
                                exp = eachlist[i + 1].get_text()
                            if '年龄：' in result or 'Age：' in result:
                                age = eachlist[i + 1].get_text()
                            if '性别：' in result or 'Sex：' in result:
                                sex = eachlist[i + 1].get_text()
                            if '婚姻状况：' in result or 'Marital Status：' in result:
                                wed = eachlist[i + 1].get_text()
                            if '手机号码：' in result or 'Cell/Telephone：' in result:
                                tel = eachlist[i + 1].get_text()
                            if '电子邮件：' in result or 'Email：' in result:
                                mail = eachlist[i + 1].get_text()
                            if '期望地点：' in result or 'Sex：' in result:
                                city = eachlist[i + 1].get_text()
                            if '所在地：' in result or 'Household：' in result:
                                place = eachlist[i + 1].get_text()
                            if '期望年薪：' in result or 'Expected Income：' in result:
                                if('勿推企业：'in eachlist[i + 1].get_text()):
                                    salary = eachlist[i + 2].get_text()
                                else:
                                    salary = eachlist[i + 2].get_text()
                            if ('教育程度：' in result or 'Attainment：' in result) and edu == '':
                                edu = eachlist[i + 1].get_text()
                            if ('Positions Held：' in result or '所任职位：' in result) and work == '':
                                work = eachlist[i + 1].get_text()
                            if ('Company Name：' in result or '公司名称：' in result) and company == '':
                                company = eachlist[i + 1].get_text()
                            if ('专业：' in result) and master == '':
                                masterlist = eachlist[i].get_text().split('：')
                                master = masterlist[1]
                                schoollist = eachlist[i - 1].get_text().split('（')
                                school = schoollist[0]
                            if (edu == result) and edu != '' and ( '教育程度：' not in eachlist[i - 1].get_text() or 'Attainment：' not in eachlist[i - 1].get_text()):
                                master = eachlist[i - 1].get_text()
                                school = eachlist[i - 2].get_text()
                            if '姓名：' in result or 'Name：' == result:
                                name = eachlist[i + 1].get_text()
                            if '简历更新时间：' in result or '更新日期：' in result or 'Latest Update：' in result:
                                if re.findall('\d{4}-\d{2}-\d{2}', eachlist[i].get_text()) != []:
                                    time = re.findall('\d{4}-\d{2}-\d{2}', eachlist[i].get_text())[0]
                            if '期望地点：' in result or 'Expected Location：' in result:
                                city = eachlist[i + 1].get_text()
                            if '教育经历' == job1 or 'EducationalExperience'== job1:
                                edutag = 1
                            if '工作经历' == job1 or 'WorkExperience'== job1:
                                worktag = 1
                            if job1 in ['项目经历', '教育经历', 'EducationalExperience', 'ProjectExperience']:
                                worktag = -1
                            if job1 in ['语言能力', '自我评价', '培训经历', '附加信息', 'Languages', 'AdditionalInformation']:
                                edutag = -1
                            if (worktag == 1 and job1 != ''):
                                workexptxt.append(result)
                                if (re.findall('\d{4}.\d{2}-',job1) != []):
                                    worknumber = worknumber+1
                            if (edutag == 1 and job1 != ''):
                                eduexptxt.append(result)
                                if (re.findall('\d{4}.\d{2}-',job1) != [] or re.findall('\d{4}',job1) != [] ):
                                    edunumber = edunumber+1
                        except Exception:
                            continue
                try:
                    for i in range(0,edunumber):
                        try:
                            eduStartTime = ''
                            eduEndTime = ''
                            eduSchool = ''
                            eduMaster = ''
                            eduTemplate = {
                                "eduStart": "",
                                "eduEnd": "",
                                "education": "",
                                "eduSchool": "",
                                "eduMaster": ""}
                            if (int((len(eduexptxt) - 1) / 4) == edunumber):
                                edutex = eduexptxt[i * 4 + 1].split('（')
                                eduTime = re.sub('）', '', edutex[1])
                                eduStartTime = eduTime.split('-')[0]
                                eduEndTime = eduTime.split('-')[1]
                                eduSchool = edutex[0]
                                eduMaster = eduexptxt[i * 4 + 2].split('：')[1]
                                education = eduexptxt[i * 4 + 3].split('：')[1]
                            elif (int((len(eduexptxt) - 1) / 3) == edunumber):
                                edutex = eduexptxt[i * 3 + 1].split('   ')
                                eduTime = edutex[1]
                                eduStartTime = eduTime.split('–')[0]
                                eduEndTime = eduTime.split('–')[1]
                                eduSchool = edutex[0]
                                eduMaster = eduexptxt[i * 3 + 2]
                                education = eduexptxt[i * 3 + 3]
                            eduTemplate['eduStart'] = eduStartTime
                            eduTemplate['eduEnd'] = eduEndTime
                            eduTemplate['education'] = education
                            eduTemplate['eduSchool'] = eduSchool
                            eduTemplate['eduMaster'] = eduMaster
                            if (i == edunumber - 1):
                                eduexplist = eduexplist + json.dumps(eduTemplate)
                            else:
                                eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                        except Exception:
                            continue
                except Exception:
                    print("###########猎聘2教育经历#############")
                eduexplist = eduexplist + ']'
                try:
                    for i in range(0, worknumber):
                        try:
                            workTitle = ''
                            workCompany = ''
                            startTime = ''
                            endTime = ''
                            workContent = ''
                            workTemplate = {
                                "startTime": "#STARTTIME#",
                                "endTime": "#ENDTIME#",
                                "workCompany": "#WORKCOMPANY#",
                                "workTitle": "#WORKTITLE#",
                                "workContent": "#WORKCONTENT#"}
                            if((len(workexptxt)-1)%8==0):
                                workTime = workexptxt[i * 8 + 1]
                                startTime = workTime.split('-')[0]
                                endTime = workTime.split('-')[1]
                                workCompany = workexptxt[i * 8 + 2]
                                workTitle = workexptxt[i * 8 + 5]
                                workContent = workexptxt[i * 8 + 8]
                            elif((len(workexptxt)-1)%11==0):
                                workTime = workexptxt[i * 11 + 1]
                                startTime = re.sub('\s', '', workTime.split('-')[0])
                                endTime = re.sub('\s', '', workTime.split('-')[1])
                                workCompany = workexptxt[i * 11 + 2]
                                workTitle = workexptxt[i * 11 + 4]
                                workContent = workexptxt[i * 11 + 11]
                            workTemplate['startTime'] = startTime
                            workTemplate['endTime'] = endTime
                            workTemplate['workTitle'] = workTitle
                            workTemplate['workCompany'] = workCompany
                            workTemplate['workContent'] = workContent
                            if (i == worknumber - 1):
                                workexplist = workexplist + json.dumps(workTemplate)
                            else:
                                workexplist = workexplist + json.dumps(workTemplate) + ','
                        except Exception:
                            continue
                except Exception:
                    print("###########猎聘2doc工作经历#############")
                workexplist = workexplist + ']'
            except Exception:
                return []
        people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary, exp,company,workexplist,eduexplist]
        people = []
        for message in people1:
            if (message != None):
                message = re.sub('\n', '', message)
                message = re.sub('\s', '', message)
                message = re.sub('\r', '', message)
                message = re.sub('\|', '', message)
            else:
                message = ''
            people.append(message)
        return people
    def tongcheng58(self, filename):
        soup = self.soup
        [s.extract() for s in soup('head')]
        [s.extract() for s in soup('script')]
        [s.extract() for s in soup('img')]
        [s.extract() for s in soup('link')]
        [s.extract() for s in soup('style')]
        ###空值定义区,防数值重复
        name = ''
        time = ''
        sex = ''
        age = ''
        edu = ''
        tel = ''
        mail = ''
        exp = ''
        place = ''
        city = ''
        wed = ''
        school = ''
        salary = ''
        master = ''
        work = ''
        company = ''
        eduexplist = '['
        workexplist = '['
        people = []
        try:
            try:
                name = soup.find('span', class_="name").get_text()
            except Exception:
                print("###########提取姓名错误#############")
            try:
                sexAge = soup.find('span', class_="sexAge").get_text()
                sexAge = re.sub('（', '', sexAge)
                sexAge = re.sub('）', '', sexAge)
                sexlist = sexAge.split('，')
                for each in sexlist:
                    if each in ['男', '女']:
                        sex = each
                    if '岁' in each:
                        age = re.findall('.*?岁', each)[0]
            except Exception:
                print("###########提取性别、年龄信息错误#############")
            try:
                timebasic = soup.find('a', class_="refreshTime f-58").get_text()
                timelist = timebasic.split("：")
                time = timelist[1]
            except Exception:
                print("###########提取更新时间信息错误#############")
            try:
                tel = soup.find('span', class_="ored").get_text()
            except Exception:
                print("###########提取电话号码错误#############")
            basic = soup.find('div', class_="expectTitle")
            basiclist = basic.select('ul')
            try:
                edulist = basiclist[0].get_text()
                edulist = re.sub('\n', '', edulist)
                edulist = re.sub('\s', '', edulist)
                edulist = re.sub('\r', '', edulist)
                edulist2 = edulist.split("|")
                for each in edulist2:
                    if '现居' in each:
                        each = re.sub('现居', '', each)
                        place = each
                    if '工作经验' in each:
                        exp = each
                    if each in ['已婚', '未婚', '离异', '丧偶', '保密']:
                        wed = each
                    if each in ['本科', '硕士', '博士', '专科', '大专', '高中', '初中', '小学']:
                        edu = each
            except Exception:
                print("###########提取居住地、工作经验、学历信息错误#############")
            try:
                explist = basiclist[1].get_text()
                explist = re.sub('\n', '', explist)
                explist = re.sub('\s', '', explist)
                explist = re.sub('\r', '', explist)
                explist2 = explist.split("|")
                explist2[1] = re.sub('想在', '', explist2[1])
                explist2[1] = re.sub('工作', '', explist2[1])
                city = explist2[1]
                explist2[2] = re.sub('期望薪资', '', explist2[2])
                salary = explist2[2]
            except Exception:
                print("###########提取期望工作地点、期望薪资信息错误#############")
            try:
                edubasic = soup.find('div', class_="addcont addeduc")
                edulist = edubasic.find_all('div', class_="infoview noborder")
                for i in range(0, len(edulist)):
                    try:
                        eduStartTime = ''
                        eduEndTime = ''
                        eduSchool = ''
                        eduMaster = ''
                        eduTemplate = {
                            "eduStart": "",
                            "eduEnd": "",
                            "education": "",
                            "eduSchool": "",
                            "eduMaster": ""}
                        edubasiclist = edulist[i].select('li')
                        # eduTime = re.sub('）', '', edutex[1])
                        # eduStartTime = eduTime.split('-')[0]
                        eduEndTime = edubasiclist[0].get_text()
                        eduSchool = edubasiclist[1].get_text()
                        eduMaster = edubasiclist[2].get_text()
                        education = edu
                        eduTemplate['eduStart'] = eduStartTime
                        eduTemplate['eduEnd'] = eduEndTime
                        eduTemplate['education'] = education
                        eduTemplate['eduSchool'] = eduSchool
                        eduTemplate['eduMaster'] = eduMaster
                        if(i==0):
                            school = eduSchool
                            master = eduMaster
                        if (i == len(edulist) - 1):
                            eduexplist = eduexplist + json.dumps(eduTemplate)
                        else:
                            eduexplist = eduexplist + json.dumps(eduTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########58同城教育经历#############")
            eduexplist = eduexplist + ']'
            try:
                workbasic = soup.find('div', class_="addcont addexpe")
                worklist= workbasic.find_all('div', class_="infoview")
                for i in range(0, len(worklist)):
                    try:
                        workTitle = ''
                        workCompany = ''
                        startTime = ''
                        endTime = ''
                        workContent = ''
                        workTemplate = {
                            "startTime": "#STARTTIME#",
                            "endTime": "#ENDTIME#",
                            "workCompany": "#WORKCOMPANY#",
                            "workTitle": "#WORKTITLE#",
                            "workContent": "#WORKCONTENT#"}
                        workCompany = worklist[i].select('h4')[0].get_text()
                        worktxtlist = worklist[i].find_all('p',class_="pst")
                        for j in range(0,len(worktxtlist)):
                            if('工作时间：' in worktxtlist[j].get_text()):
                                workTime1 = re.sub('工作时间：','',worktxtlist[j].get_text())
                                workTime = workTime1.split('[')
                                startTime = re.sub('\s', '', workTime[0].split('-')[0])
                                endTime = re.sub('\s', '', workTime[0].split('-')[1])
                            elif('在职职位：' in worktxtlist[j].get_text()):
                                workTitle = re.sub('在职职位：','',worktxtlist[j].get_text())
                        worktxtContent = worklist[i].find('p',class_="pst2")
                        if(worktxtContent!=None  and '工作职责：' in  worktxtContent.get_text()):
                            workContent=re.sub('工作职责：','', worktxtContent.get_text())
                            workContent=re.sub('\s','',workContent)
                        workTemplate['startTime'] = startTime
                        workTemplate['endTime'] = endTime
                        workTemplate['workTitle'] = workTitle
                        workTemplate['workCompany'] = workCompany
                        workTemplate['workContent'] = workContent
                        if (i == len(worklist)-1):
                            workexplist = workexplist + json.dumps(workTemplate)
                        else:
                            workexplist = workexplist + json.dumps(workTemplate) + ','
                    except Exception:
                        continue
            except Exception:
                print("###########猎聘1工作经历#############")
            workexplist = workexplist + ']'
            # ['文件名','更新时间','姓名','性别','年龄','手机号','邮箱','学历','婚姻','所在地','学校','专业','最近工作职位','期望工作地点','期望薪资','工作年限'])
            people1 = [time, name, sex, age, tel, mail, edu, wed, place, school, master, work, city, salary,exp,company,workexplist,eduexplist]
            people = []
            for each in people1:
                if (each != None):
                    each = re.sub('\n', '', each)
                    each = re.sub('\s', '', each)
                    each = re.sub('\r', '', each)
                    each = re.sub('\|', '', each)
                else:
                    each = ''
                people.append(each)
        except Exception:
            return []
        return people